/*     */ package com.zimbra.cs.mailbox;
/*     */ 
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.mime.ParsedMessage;
/*     */ import java.util.List;
/*     */ import java.util.Set;
/*     */ import java.util.concurrent.CopyOnWriteArrayList;
/*     */ import java.util.concurrent.CopyOnWriteArraySet;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public abstract class MetadataCallback
/*     */ {
/*  30 */   private static Set<String> sCallbackKeys = new CopyOnWriteArraySet();
/*  31 */   private static List<MetadataCallback> sCallbacks = new CopyOnWriteArrayList();
/*     */   private final String mSectionKey;
/*     */   private static String CONVERSATION_METADATA;
/*     */   
/*     */   public static synchronized void addCallback(MetadataCallback callback) {
/*  36 */     if (callback == null) {
/*  37 */       ZimbraLog.mailbox.error("", new IllegalStateException("MetadataCallback cannot be null"));
/*  38 */     } else if (sCallbackKeys.contains(callback.getMetadataSectionKey())) {
/*  39 */       ZimbraLog.mailbox.error("", new IllegalStateException("second MetadataCallback for key " + callback.getMetadataSectionKey()));
/*     */     } else {
/*  41 */       ZimbraLog.mailbox.info("Adding metadata callback: %s", new Object[] { callback.getClass().getName() });
/*  42 */       sCallbacks.add(callback);
/*  43 */       sCallbackKeys.add(callback.getMetadataSectionKey());
/*     */     }
/*     */   }
/*     */   
/*     */   public static boolean isSectionRegistered(String key) {
/*  48 */     return sCallbackKeys.contains(key);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   protected MetadataCallback(String key)
/*     */   {
/*  55 */     if ((key == null) || (key.trim().equals("")))
/*  56 */       throw new IllegalArgumentException("metadata callback section key cannot be blank");
/*  57 */     this.mSectionKey = key;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   protected String getMetadataSectionKey()
/*     */   {
/*  67 */     return this.mSectionKey;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static MailItem.CustomMetadata.CustomMetadataList preDelivery(ParsedMessage pm)
/*     */   {
/*  80 */     if ((pm == null) || (sCallbacks.isEmpty())) {
/*  81 */       return null;
/*     */     }
/*  83 */     MailItem.CustomMetadata.CustomMetadataList extended = null;
/*  84 */     for (MetadataCallback callback : sCallbacks) {
/*  85 */       MailItem.CustomMetadata custom = callback.analyzeMessage(pm);
/*  86 */       if (custom != null) {
/*  87 */         if (extended == null) {
/*  88 */           extended = custom.asList();
/*     */         } else
/*  90 */           extended.addSection(custom);
/*     */       }
/*     */     }
/*  93 */     return extended;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   static
/*     */   {
/* 108 */     MailItem.CustomMetadata meta = new MailItem.CustomMetadata("ignored");
/* 109 */     meta.put("_exists", "1");
/* 110 */     CONVERSATION_METADATA = meta.getSerializedValue();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static MailItem.CustomMetadata.CustomMetadataList duringConversationAdd(MailItem.CustomMetadata.CustomMetadataList extended, Message msg)
/*     */   {
/* 128 */     if (msg == null) {
/* 129 */       return extended;
/*     */     }
/* 131 */     List<String> msgSections = msg.getCustomDataSections();
/* 132 */     if ((msgSections != null) && (!msgSections.isEmpty())) {
/* 133 */       for (String key : msgSections) {
/* 134 */         if (extended == null)
/* 135 */           extended = new MailItem.CustomMetadata.CustomMetadataList();
/* 136 */         extended.addSection(key, CONVERSATION_METADATA);
/*     */       }
/*     */     }
/* 139 */     return extended;
/*     */   }
/*     */   
/*     */   protected abstract MailItem.CustomMetadata analyzeMessage(ParsedMessage paramParsedMessage);
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/mailbox/MetadataCallback.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */